package cc.wangweiye.eakun;

import cn.hutool.json.JSONUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class EakunApplication {

    public static void main(String[] args) {
        SpringApplication.run(EakunApplication.class, args);
    }


    @PostMapping
    public String receive(@RequestBody String s) {
        // 1. 抓拍事件 2. 客流统计 3. 设备状态
        int type = JSONUtil.parseObj(s).getInt("type");
        switch (type) {
            case 1:
                System.out.println("抓拍事件");
                Snap snap = JSONUtil.toBean(s, Snap.class);
                System.out.println(snap.toString());
                break;
            case 3:
                System.out.println("设备状态");
                DeviceInfo info = JSONUtil.toBean(s, DeviceInfo.class);
                System.out.println(info.toString());
                break;
        }
        return "ok";
    }
}
